package com.itboye.jinpuyiyuan.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.bean.DateBean;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/12/18 0018.
 */

public class DateRecylerAdapter extends RecyclerView.Adapter<DateRecylerAdapter.MyViewHolder> {
    private ArrayList<DateBean> list;
    private Context context;
    private LayoutInflater inflater;
    private int selectId=0;
    private OnItemClickListener onItemClickListener;
    public DateRecylerAdapter(Context context,ArrayList<DateBean> list){
        this.context=context;
        this.list=list;
        inflater=LayoutInflater.from(context);

    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = inflater.inflate(R.layout.item_daterecycler, parent, false);
        MyViewHolder myViewHolder = new MyViewHolder(inflate);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        if (position==selectId){ //选中id
            holder.monthTv.setText(list.get(position).getMonth()+"-"+list.get(position).getDay());
            holder.weekTv.setText(list.get(position).getWeek());
            holder.monthTv.setTextSize(15);
            holder.monthTv.setTextColor(context.getResources().getColor(R.color.title_blue));
            holder.weekTv.setTextSize(15);
            holder.weekTv.setTextColor(context.getResources().getColor(R.color.title_blue));
        }else {
            holder.monthTv.setText(list.get(position).getMonth()+"-"+list.get(position).getDay());
            holder.weekTv.setText(list.get(position).getWeek());
            holder.monthTv.setTextSize(12);
            holder.monthTv.setTextColor(context.getResources().getColor(R.color.black));
            holder.weekTv.setTextSize(12);
            holder.weekTv.setTextColor(context.getResources().getColor(R.color.black));
        }
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemClickListener!=null){
                        onItemClickListener.onItemClick(holder.itemView, position);
                    }
                }
            });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView weekTv,monthTv;
        View itemView;
        public MyViewHolder(View itemView) {
            super(itemView);
            this.itemView=itemView;
         itemView.setClickable(true);
         weekTv = itemView.findViewById(R.id.weekTv);
         monthTv = itemView.findViewById(R.id.monthTv);
        }
    }
    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }
    public void setSelectId(int position){
        this.selectId=position;
        this.notifyDataSetChanged();
    }
    public void setOnItemClickListener(OnItemClickListener mOnItemClickLitener) {
        this.onItemClickListener = mOnItemClickLitener;
    }
}
